jQuery(document).ready( function() {	
	jQuery('.resetPasswordButton').on('click', function() {
 	    jQuery('.actionResult').hide();
		var userName = jQuery('.userName').text();
		var userEmail = jQuery('.userEmail').text();
		jQuery.ajax({
	            url : "resetPassword",
	            type: "POST",
	            dataType: 'text',
	            data:  { name: userName, email: userEmail },
	            success : function(msg) {
	            	jQuery('.searchResult').hide();
	  	    	   	jQuery('.doubleButtons').hide();
	 	    	    jQuery('.actionResult').html(msg);
	 	    	    jQuery('.actionResult').show();
	 	    	}
	    });
	});
	
	jQuery(".removeUserButton").on('click', function() {
 	    jQuery('.actionResult').hide();
		var userName = jQuery('.userName').text();
		var userEmail = jQuery('.userEmail').text();
		jQuery.ajax({
            url : "deleteUser",
            type: "POST",
            dataType: 'text',
            data:  { name: userName, email: userEmail },
            success : function(msg) {
            	jQuery('.searchResult').hide();
  	    	   	jQuery('.doubleButtons').hide();
 	    	    jQuery('.actionResult').html(msg);
 	    	    jQuery('.actionResult').show();
 	    	}
		});
	});
	
	//show form for adding user
	jQuery('.addNewStudentButton').on('click', function() {
 	    jQuery('.actionResult').hide();
		jQuery('.message').hide();
		jQuery('.addAdmin').hide();
		jQuery('.addStudent').show();
		jQuery('.addProfessor').hide();		
	});
	
	jQuery('.addNewProfessorButton').on('click', function() {
 	    jQuery('.actionResult').hide();
		jQuery('.message').hide();
		jQuery('.addAdmin').hide();
		jQuery('.addStudent').hide();
		jQuery('.addProfessor').show();
	});
	
	jQuery('.addNewAdminButton').on('click', function() {
 	    jQuery('.actionResult').hide();
		jQuery('.message').hide();
		jQuery('.addAdmin').show();
		jQuery('.addStudent').hide();
		jQuery('.addProfessor').hide();
	});
	
	//Add user
	jQuery('.addStudentButton').on('click', function() {	
		var userName = jQuery('.addStudent .userName').val();
		var faculity = jQuery('.addStudentSelect').find(":selected").text();
		jQuery.ajax({
	            url : "addUser",
	            type: "POST",
	            dataType: 'text',
	            data:  { role: "student", name: userName, faculity: faculity },
	            success : function(msg) {
	            	jQuery('.message').html(msg);
	            	jQuery('.message').show();
	        		jQuery('.addStudent').hide();
	 	    	}
	    });
	});
	
	jQuery('.addProfessorButton').on('click', function() {	
		var userName = jQuery('.addProfessor .userName').val();
		var faculity = jQuery('.addProfessorSelect').find(":selected").text();
		jQuery.ajax({
	            url : "addUser",
	            type: "POST",
	            dataType: 'text',
	            data:  { role: "professor", name: userName, faculity: faculity },
	            success : function(msg) {
	            	jQuery('.message').html(msg);
	            	jQuery('.message').show();
	        		jQuery('.addProfessor').hide();	
	 	    	}
	    });
	});
	
	jQuery('.addAdminButton').on('click', function() {
		var userName = jQuery('.addAdmin .userName').val();
		jQuery.ajax({
	            url : "addUser",
	            type: "POST",
	            dataType: 'text',
	            data:  { role: "admin", name: userName },
	            success : function(msg) {
	            	jQuery('.message').html(msg);
	            	jQuery('.message').show();
	        		jQuery('.addAdmin').hide();
	 	    	}
	    });
	});
	
});